{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e7e6274f",
   "metadata": {},
   "source": [
    "# 上周内容\n",
    "\n",
    "> 1.api文档阅读（考试）\n",
    ">\n",
    "> 2.request模块（考试)\n",
    ">\n",
    "> 3.百度通用图像识别"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "791418c7",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "1. 人脸识别概念和基础\n",
    "\n",
    "2.人脸识别应用\n",
    "\n",
    "3.人脸识别实践-face++\n",
    "\n",
    "> 1.人脸检测\n",
    ">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "333ecc9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "人脸检测概念和识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "175bbe94",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678679370,221f1105-d9e1-48e1-8ee1-38c4100f5bcb', 'time_used': 201, 'faces': [{'face_token': '50ff8766084ad7e45dffa01fc349d73f', 'face_rectangle': {'top': 146, 'left': 155, 'width': 181, 'height': 181}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 19}, 'smile': {'value': 11.521, 'threshold': 50.0}, 'headpose': {'pitch_angle': -12.950522, 'roll_angle': -12.772529, 'yaw_angle': 66.16048}, 'blur': {'blurness': {'value': 54.593, 'threshold': 50.0}, 'motionblur': {'value': 54.593, 'threshold': 50.0}, 'gaussianblur': {'value': 54.593, 'threshold': 50.0}}, 'emotion': {'anger': 14.329, 'disgust': 1.488, 'fear': 79.254, 'happiness': 1.485, 'neutral': 2.954, 'sadness': 0.245, 'surprise': 0.245}, 'facequality': {'value': 0.006, 'threshold': 70.1}}}], 'image_id': 'DHBv0AhXWOC1tycIVOWRgQ==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "FACE++ 人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('wje.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "payload={\n",
    "    'api_key':'1fhU_tz8rD0DOy0n-mvIwU0KC2XHAL8g',\n",
    "    'api_secret':'tQVlmCPZZrl9fnht5D1OCdIxgXiJp4_l',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,emotion,blur'\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9723671b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
